#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include "settings.h"
#include "formText.h"
#include "errors.h"
#include "formText.h"
#include "analys.h"

void ShowAnswer(Text *arrayReferenceText, int similarTextIndex, float maxTextAverage)
{
	if (maxTextAverage > 10)
	{
		printf("\n\nTopic text is \"%s\".\n", arrayReferenceText[similarTextIndex].topicName);
		printf("Similarity percentage is %.1f\n", maxTextAverage);
	}
	else
	{
		printf("\n\nTopic text is not defined.\n");
	}
}

int main()
{
	setlocale(LC_ALL, "");
	Text analysingText = {"", 0, NULL, 0};
	int numReferenceText = 0;
	Text *arrayReferenceText = NULL;
	TempWord *stopWord = NULL;
	float maxTextAverage = 0;
	int similarTextIndex = -1;

	printf("Initialisation global variable and structure.\n");	
	printf("Loading stop words.\n");
	stopWord = ReadStopWord();

	printf("Loading, process reference text.\n");
	arrayReferenceText = ReadCategoryList(&numReferenceText, arrayReferenceText, stopWord);

	printf("Loading, process analyzed text.\n");
	analysingText = ReadAnalyzedText(analysingText, stopWord);

	AnalysText(&numReferenceText, arrayReferenceText, &analysingText, &similarTextIndex, &maxTextAverage);
	ShowAnswer(arrayReferenceText, similarTextIndex, maxTextAverage);

	FreeMem(arrayReferenceText, numReferenceText);

	getchar();
	return 0;
}